#include<iostream>
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        if (strs.size() == 0)return "";
        string str = strs[0];
        for (int i = 1; i < strs.size(); i++)
            if (strs[i].length() < str.length()) str = strs[i];
           
        for (int i = 0; i < strs.size(); i++)
        {
            int n = str.length();
            n = n < strs[i].length() ? n : strs[i].length();
            for (int j = 0; j < n; j++)
            {
                if (str[j] != strs[i][j])
                {
                    str = str.substr(0, j);
                    break;
                }
            }

        }
        return str;
    }
};
int main()
{
    Solution sol;
    vector<string> strs;
    strs.push_back("ca");
    strs.push_back("a");
    cout << sol.longestCommonPrefix(strs);
}